import { http } from '@/utils/http'

export interface SessionRes {
  accessToken: string
  /** 用于调用刷新`accessToken`的接口时所需的`token` */
  refreshToken: string
  /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
  expiresIn: Date
}
/** 登录 */
export const getSession = (data?: object) => {
  // return http.request<UserResult>('post', '/login', { data })
  return http.request<SessionRes>('post', '/api/sessions', {
    data
  })
}

/** 刷新`token` */
export const refreshTokenApi = (data?: object) => {
  // return http.request<RefreshTokenResult>('post', '/refresh-token', { data })
  return http.request<SessionRes>('put', '/api/sessions', { data })
}

export const logout = () => {
  return http.request('delete', '/api/sessions')
}
